#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    string str, tmp, ans;
    cin >> n;
    cin.ignore();
    for(int i = 0; i < n; ++i){
        getline(cin, str);
        stringstream ss;
        ss << str;
        ans = "";
        while(ss >> tmp){
            reverse(tmp.begin(), tmp.end());
            ans += tmp;
            ans += " ";
        }
        ans.pop_back();
        cout << ans << endl;
    }
}